package com.xb.system.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lzy
 * @create 2024/11/4 15:52
 */
@Component
@ConfigurationProperties(prefix = "file.txtdata")
@Data
public class TxtDataV1Config {
    private List<Integer> indexes = new ArrayList<>();
    private String range; // YAML 中的范围表达式

    // 使用 @PostConstruct 在对象构建之后解析范围表达式
    @PostConstruct
    public void init() {
        if (range != null && range.contains("-")) {
            indexes = new ArrayList<>();
            String[] parts = range.split("-");
            int start = Integer.parseInt(parts[0]);
            int end = Integer.parseInt(parts[1]);
            for (int i = start; i <= end; i++) {
                indexes.add(i);
            }
        }
    }
}